package main

import (
	"net"
	"os"
	"bytes"
	"io"
)

func main() {

	conn,err := net.Dial("tcp","open.u51.com:80")
	checkError(err)

	_,err2 :=conn.Write([]byte("HEAD HTTP/1.1\r\n\r\n"))
	checkError(err2)

	result,err := readFully(conn)
	checkError(err)

	println(string(result))

	os.Exit(0)
}

func checkError(err error)  {
	if err!=nil {
		println("error",err.Error())
		os.Exit(1)
	}
}

func readFully(conn net.Conn)([]byte,error)  {
	defer conn.Close()

	results := bytes.NewBuffer(nil)
	var buf [512]byte
	for  {
		n,err :=conn.Read(buf[0:])
		results.Write(buf[0:n])
		if err != nil {
			if err == io.EOF{
				break
			}
			return nil,err
		}

	}
	return results.Bytes(),nil
}
